﻿using System;
using System.Data.SQLite;
using System.Windows.Forms;

namespace CSharp大作业
{
    public partial class Form4 : Form
    {
        public Form4()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string name = textBox1.Text;
            if (string.IsNullOrEmpty(name))
            {
                MessageBox.Show("请输入名称。");
                return;
            }

            using (var conn = new SQLiteConnection("Data Source=Storage\\minesweeper.db;Version=3;"))
            {
                conn.Open();
                var cmd = new SQLiteCommand("INSERT INTO Leaderboard (Name, Score, Mines) VALUES (@Name, @Score, @Mines)", conn);
                cmd.Parameters.AddWithValue("@Name", name);
                cmd.Parameters.AddWithValue("@Score", CSharp大作业.Form1.CostTime);  // 确保Form1有静态公共变量CostTime和MineNum
                cmd.Parameters.AddWithValue("@Mines", CSharp大作业.Form1.MineNum);
                cmd.ExecuteNonQuery();
            }
            this.Close();
        }

        private void Form4_Load(object sender, EventArgs e)
        {

        }
    }
}
